package com.grass.appointment.model;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.JsonParams;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.google.gson.Gson;
import com.grass.appointment.bean.SaveCover;
import com.grass.appointment.bean.UploadImgBean;
import java.io.File;
import java.util.List;

public class SaveCoverModel extends ViewModel {
    private MutableLiveData<BaseRes> deleteCover;
    private MutableLiveData<BaseRes> saveCover;
    private MutableLiveData<BaseRes<UploadImgBean>> uploadImage;

    public MutableLiveData<BaseRes> getDeleteCover() {
        if (this.deleteCover == null) {
            this.deleteCover = new MutableLiveData<>();
        }
        return this.deleteCover;
    }

    public MutableLiveData<BaseRes> getSaveCover() {
        if (this.saveCover == null) {
            this.saveCover = new MutableLiveData<>();
        }
        return this.saveCover;
    }

    public MutableLiveData<BaseRes<UploadImgBean>> imageData() {
        if (this.uploadImage == null) {
            this.uploadImage = new MutableLiveData<>();
        }
        return this.uploadImage;
    }

    public void upLoadImageCover(final List<String> list) {
        String uploadImg = UrlManager.getInsatance().uploadImg();
        if (list.size() <= 0) {
            BaseRes<UploadImgBean> baseRes = new BaseRes<>();
            baseRes.setCode(100);
            this.uploadImage.setValue(baseRes);
            return;
        }
        HttpUtils.getInsatance().post_form(uploadImg, new File(list.get(0)), new HttpCallback<BaseRes<UploadImgBean>>("uploadImg") {
            /* class com.grass.appointment.model.SaveCoverModel.C28441 */

            public void onLvSuccess(BaseRes<UploadImgBean> baseRes) {
                SaveCoverModel.this.uploadImage.setValue(baseRes);
                list.remove(0);
                SaveCoverModel.this.upLoadImageCover(list);
            }
        });
    }

    public void saveCover(List<String> list) {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().saveCoverImage(), new Gson().toJson(new SaveCover(list)), new HttpCallback<BaseRes<String>>("saveCoverImage") {
            /* class com.grass.appointment.model.SaveCoverModel.C28452 */

            public void onLvSuccess(BaseRes<String> baseRes) {
                SaveCoverModel.this.saveCover.setValue(baseRes);
            }
        });
    }

    public void deleteCover(String str) {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().deleteCoverImage(), JsonParams.build().add("bgImg", str).commit(), new HttpCallback<BaseRes<String>>("deleteCoverImage") {
            /* class com.grass.appointment.model.SaveCoverModel.C28463 */

            public void onLvSuccess(BaseRes<String> baseRes) {
                SaveCoverModel.this.deleteCover.setValue(baseRes);
            }
        });
    }

    public void cancelHttp() {
        HttpUtils.getInsatance().cancelTag("deleteCoverImage");
        HttpUtils.getInsatance().cancelTag("saveCoverImage");
        HttpUtils.getInsatance().cancelTag("uploadImg");
    }
}
